import React, {Component} from 'react';
import {
    View,
    Text,
    Image,
    TouchableOpacity,
} from 'react-native';


import {positionthreeStyle as styles} from '../../../../../styles';
import Icon from 'react-native-vector-icons/Ionicons';

var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;          //获取屏幕宽度
import Company from '../../company/company';
import {common_url} from "../../../../util/fetch";


export default class Posthree extends Component {
    constructor(props) {            //构造器只执行一次
        super(props);
    };

    render() {
        if (this.props.xzPostion.company == undefined) {
            return (
                <TouchableOpacity activeOpacity={1} style={[styles.postthreetop, {width: width * 1}]} onPress={() => {
                    this.props.navigation.navigate('Company')
                }}>
                    <Image source={require('../../../../img/app/company.png')} style={styles.head}/>
                    <View style={styles.name}>
                        <Text style={styles.comname}></Text>
                        <View style={styles.allname}>
                            <Text style={styles.namein}></Text>
                            <Text style={styles.namein}></Text>
                            <Text style={styles.namein}></Text>
                        </View>
                    </View>

                    <Icon
                        name={'ios-arrow-forward'}
                        size={23}
                        color={'#949494'} style={styles.posicon1}/>

                </TouchableOpacity>
            )
        } else {
            return (
                <TouchableOpacity
                    activeOpacity={1}
                    style={[styles.postthreetop, {width: width * 1}]}
                    onPress={() => {
                        this.goGet('Company', this.props.xzPostion.companyId);
                    }}
                >
                    <Image source={
                        this.props.xzPostion.company.companyPicture ?
                            {uri: common_url + "uploadImg/" + this.props.xzPostion.company.companyPicture}
                            : require('../../../../img/app/company.png')} style={styles.head}/>
                    <View style={styles.name}>
                        <Text style={styles.comname}>{this.props.xzPostion.company.companyName}</Text>
                        <View style={styles.allname}>
                            <Text style={styles.namein}>{this.fieldName(this.props.xzPostion.company.fields, 1)}</Text>
                            <Text style={styles.namein}>{this.props.xzPostion.company.companyScale}</Text>
                            <Text style={styles.namein}>{this.Nature(this.props.xzPostion.company.companyNature)}</Text>
                        </View>
                    </View>

                    <Icon
                        name={'ios-arrow-forward'}
                        size={23}
                        color={'#949494'} style={styles.posicon1}/>

                </TouchableOpacity>
            )
        }
    }

    Nature(nature) {
        var str = "";
        if (nature == 1) {
            str = '国企';
        } else if (nature == 2) {
            str = '民营';
        } else if (nature == 3) {
            str = '外企';
        } else if (nature == 4) {
            str = '政府';
        }
        return str;
    }

    //经营领域
    fieldName(List, sl) {
        var data = {
            cont: List
        }
        var arr = '';                            //用来装公司类型
        var s = sl;
        var length = data.cont.length
        if (length <= s) {
            s = length
        }
        for (var i = 0; i < s; i++) {
            arr = data.cont[i].fieldName;
        }
        return arr;
    }

    goGet(name, id) {
        this.props.navigation.navigate(name, {useId: id});
    }
}
